package com.detrum.costomview;

import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.RectF;
import android.support.annotation.Nullable;
import android.util.AttributeSet;
import android.view.View;

/**
 * Created by abc on 2018/3/27.
 */

public class SaveView extends View {
    private Paint circlePaint;
    private RectF rect;
    private int agree,percent;

    public SaveView(Context context) {
        super(context);
    }

    public SaveView(Context context, @Nullable AttributeSet attrs) {
        super(context, attrs);
        circlePaint = new Paint(Paint.ANTI_ALIAS_FLAG);
    }

    public void Percent(int percent){
        this.percent = percent;
        agree = 360-percent*360/100;
        invalidate();
    }
    @Override
    protected void onDraw(Canvas canvas) {
        super.onDraw(canvas);
        circlePaint.setColor(Color.GREEN);
        canvas.drawCircle(Math.min(getWidth()/2,getHeight()/2),getHeight()/2,Math.min(getWidth()/2,getHeight()/2),circlePaint);
        circlePaint.setColor(Color.WHITE);
        circlePaint.setTextSize(getHeight()*18/20);
        canvas.drawText(percent+"%",getHeight()*11/10,getHeight()*8.0f/10,circlePaint);
        circlePaint.setColor(Color.RED);
        RectF rectF = new RectF(0,0,getHeight(),getHeight());
        canvas.drawArc(rectF,0,agree,true,circlePaint);

    }
}
